package com.kedou.sdk.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kedou.sdk.ui.assist.OnFinishActivityListener;

public class GuestRegisterDialogFragment extends BaseDialogFragment implements View.OnClickListener {

    public static GuestRegisterDialogFragment newInstance() {
        return new GuestRegisterDialogFragment();
    }

    private View mGuestRegisterButtonView;
    private View mGuestRegisterAccountRegisterView;
    private View mGuestRegisterAccountLoginView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View contentView = doInflateContentView(inflater, container, getLayoutIdentifier("hnssn_activity_guest_register"));

        mGuestRegisterButtonView = contentView.findViewById(getViewIdentifier("activity_guest_register_sumbit_btn"));
        mGuestRegisterAccountRegisterView = contentView.findViewById(getViewIdentifier("activity_guest_register_account_register"));
        mGuestRegisterAccountLoginView = contentView.findViewById(getViewIdentifier("activity_guest_register_account_login"));

        mGuestRegisterButtonView.setOnClickListener(this);
        mGuestRegisterAccountRegisterView.setOnClickListener(this);
        mGuestRegisterAccountLoginView.setOnClickListener(this);

        return contentView;
    }

    @Override
    public void onClick(View view) {
        if(mGuestRegisterButtonView == view){
            mGuestRegisterButtonView.setEnabled(false);
            mGuestRegisterButtonView.setClickable(false);
            nextToOneKeyRegister();
            return;
        }

        if(mGuestRegisterAccountRegisterView == view){
            nextToAccountRegister();
            return;
        }

        if(mGuestRegisterAccountLoginView == view){
            nextToAccountLogin();
        }

    }


    private OnGuestActionListener getOnGuestActionListener() {
        if (!isNullContext()) {
            Activity activity = getActivity();
            if (activity instanceof OnGuestActionListener) {
                return (OnGuestActionListener) activity;
            }
        }
        return null;
    }


    private void nextToOneKeyRegister() {
        OnGuestActionListener listener = getOnGuestActionListener();
        if (listener != null) {
            listener.doNextToOneKeyLogin();
        }
    }

    private void nextToAccountRegister() {
        OnGuestActionListener listener = getOnGuestActionListener();
        if (listener != null) {
            listener.doNextToQuickRegister();
        }
    }

    private void nextToAccountLogin() {
        OnGuestActionListener listener = getOnGuestActionListener();
        if (listener != null) {
            listener.doFinishActivity(this);
        }
    }


    public interface OnGuestActionListener extends OnFinishActivityListener {

        void doNextToOneKeyLogin();

        void doNextToQuickRegister();

    }
}
